//
//  AddFriendViewController.m
//  BaChat
//
//  Created by 刘洋 on 16/6/14.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "AddFriendViewController.h"

@interface AddFriendViewController ()

@property(nonatomic,retain)UITextField *searchNameTextField;


@end

@implementation AddFriendViewController

-(void)dealloc{
    [_searchNameTextField release];
    
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.searchNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, ROOTWIDTH, 30)];
    self.searchNameTextField.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.searchNameTextField];
    [_searchNameTextField release];
    
    BaseButton *addButton = [BaseButton buttonWithType:UIButtonTypeCustom];
    addButton.frame = CGRectMake(100, 100, 100, 100);
    addButton.backgroundColor = [UIColor redColor];
    [self.view addSubview:addButton];
    [addButton setTitle:@"添加" forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addFriendButton) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    // Do any additional setup after loading the view.
}


-(void)addFriendButton{
    
    NSString *name = self.searchNameTextField.text;
  

    
//向服务器发送好友请求
    EMError *error = nil;
    [[EaseMob sharedInstance].chatManager addBuddy:name message:@"我想加您为好友" error:&error];
    if (!error) {
        NSLog(@"发送好友请求成功");
    }else{
        NSLog(@"发送好友失败");
        NSLog(@"%@",error);
    }
    
  
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
